using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class NoFSM : MonoBehaviour
{   
    private enum E_State{
        Idel,
        Run,
        Jump,
    }
    private E_State currentState;
    [SerializeField]private bool isGround;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        if(isGround)
         Idel();     
    }

    // Update is called once per frame
    void Update()
    {    
        switch(currentState){
            case E_State.Idel:
                Idel();
                break;
            case E_State.Run:
                Run();
                break;
            case E_State.Jump:
                Jump();
                break;
        }
    }


    private void ChangeState(E_State newState){
        currentState = newState;
    }
    private void Run(){
        Debug.Log("Run");
        if(Keyboard.current.spaceKey.isPressed)
            ChangeState(E_State.Jump);
        if(isGround && !Keyboard.current.wKey.isPressed)
            ChangeState(E_State.Idel);
        Shoot();
    }   

    private void Idel(){
        Debug.Log("Idel");
        if(Keyboard.current.wKey.isPressed)
            ChangeState(E_State.Run);
        else if(Keyboard.current.spaceKey.isPressed)
            ChangeState(E_State.Jump);

        Shoot();
    }

    private void Shoot(){
        if(Mouse.current.leftButton.wasPressedThisFrame)
            Debug.Log("Shoot");
    }
    private void Jump(){
        isGround =false;

        Debug.Log("Jump");
        Shoot();
    }

}
